namespace CoreLibrary.Template {

    public class StringTemplate : ITemplate {

        private const char Dollar            = '$';
        private const char AngleBracketStart = '<';
        private const char AngleBracketEnd   = '>';

        private readonly Antlr4.StringTemplate.Template _template;
        
        private StringTemplate(string input, char start, char end) {
            _template = new Antlr4.StringTemplate.Template(input, start, end);
        }

        public string Generate(TemplateParameters parameters) {
            Asserts.NotNull(_template, "Template can not be null.");
            
            foreach (var templateParam in parameters) {
                _template.Add(templateParam.Key, templateParam.Value);
            }

            return _template.Render();
        }

        public static StringTemplate Load(string input) {
            return new StringTemplate(input, Dollar, Dollar);
        }

        public static StringTemplate LoadAngleBracket(string input) {
            return new StringTemplate(input, AngleBracketStart, AngleBracketEnd);
        }

    }

}